
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class VenueRequirementComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public VenueRequirementComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public VenueRequirement SelectOne(int VenueRequirementId)
        {  
			PlacementManager.DAL.VenueRequirement_DAL o = new PlacementManager.DAL.VenueRequirement_DAL();
			o.VenueRequirementId = VenueRequirementId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.VenueRequirement VenueRequirementToReturn = new PlacementManager.VenueRequirement((int)row["VenueRequirementId"], (string)row["VenueRequirementName"], (string)row["VenueRequirementDescription"], (int)row["VenueId"], (int)row["DivisionId"]);
				return VenueRequirementToReturn;
			}
			else
			{
				PlacementManager.VenueRequirement VenueRequirementToReturnEmpty = new PlacementManager.VenueRequirement();
                return VenueRequirementToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<VenueRequirement> SelectAll(string sortExpression)
        {
            List<VenueRequirement> listVenueRequirement = new List<VenueRequirement>();
            PlacementManager.DAL.VenueRequirement_DAL o = new PlacementManager.DAL.VenueRequirement_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listVenueRequirement.Add(new VenueRequirement((int)row["VenueRequirementId"], (string)row["VenueRequirementName"], (string)row["VenueRequirementDescription"], (int)row["VenueId"], (int)row["DivisionId"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listVenueRequirement.Sort(new VenueRequirementComparer(sortExpression));
            return listVenueRequirement;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<VenueRequirement> SelectAllWDivisionId(int DivisionId, string sortExpression)
		{
			List<VenueRequirement> listVenueRequirement = new List<VenueRequirement>();
			PlacementManager.DAL.VenueRequirement_DAL o = new PlacementManager.DAL.VenueRequirement_DAL();
			o.DivisionId = DivisionId;
			DataSet ds = o.SelectAllWDivisionId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listVenueRequirement.Add(new VenueRequirement((int)row["VenueRequirementId"], (string)row["VenueRequirementName"], (string)row["VenueRequirementDescription"], (int)row["VenueId"], (int)row["DivisionId"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listVenueRequirement.Sort(new VenueRequirementComparer(sortExpression));
			return listVenueRequirement;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<VenueRequirement> SelectAllWVenueId(int VenueId, string sortExpression)
		{
			List<VenueRequirement> listVenueRequirement = new List<VenueRequirement>();
			PlacementManager.DAL.VenueRequirement_DAL o = new PlacementManager.DAL.VenueRequirement_DAL();
			o.VenueId = VenueId;
			DataSet ds = o.SelectAllWVenueId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listVenueRequirement.Add(new VenueRequirement((int)row["VenueRequirementId"], (string)row["VenueRequirementName"], (string)row["VenueRequirementDescription"], (int)row["VenueId"], (int)row["DivisionId"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listVenueRequirement.Sort(new VenueRequirementComparer(sortExpression));
			return listVenueRequirement;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(VenueRequirement o)
        {	
            PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement = new PlacementManager.DAL.VenueRequirement_DAL();
			oVenueRequirement.VenueRequirementName = o.VenueRequirementName;
			oVenueRequirement.VenueRequirementDescription = o.VenueRequirementDescription;
			oVenueRequirement.VenueId = o.VenueId;
			oVenueRequirement.DivisionId = o.DivisionId;

            return oVenueRequirement.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(string VenueRequirementName, string VenueRequirementDescription, int VenueId, int DivisionId)
        {
            PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement = new PlacementManager.DAL.VenueRequirement_DAL();

			oVenueRequirement.VenueRequirementName = VenueRequirementName;
			oVenueRequirement.VenueRequirementDescription = VenueRequirementDescription;
			oVenueRequirement.VenueId = VenueId;
			oVenueRequirement.DivisionId = DivisionId;

            return oVenueRequirement.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(VenueRequirement o)
        {	
            PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement = new PlacementManager.DAL.VenueRequirement_DAL();
			oVenueRequirement.VenueRequirementId = o.VenueRequirementId;
			oVenueRequirement.VenueRequirementName = o.VenueRequirementName;
			oVenueRequirement.VenueRequirementDescription = o.VenueRequirementDescription;
			oVenueRequirement.VenueId = o.VenueId;
			oVenueRequirement.DivisionId = o.DivisionId;

            return oVenueRequirement.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int VenueRequirementId, string VenueRequirementName, string VenueRequirementDescription, int VenueId, int DivisionId)
        {
            PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement = new PlacementManager.DAL.VenueRequirement_DAL();

			oVenueRequirement.VenueRequirementId = VenueRequirementId;
			oVenueRequirement.VenueRequirementName = VenueRequirementName;
			oVenueRequirement.VenueRequirementDescription = VenueRequirementDescription;
			oVenueRequirement.VenueId = VenueId;
			oVenueRequirement.DivisionId = DivisionId;

            return oVenueRequirement.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(VenueRequirement o)
        {
            PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement_DAL = new PlacementManager.DAL.VenueRequirement_DAL();
            oVenueRequirement_DAL.VenueRequirementId = o.VenueRequirementId;
            return oVenueRequirement_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int VenueRequirementId)
        {
            PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement_DAL = new PlacementManager.DAL.VenueRequirement_DAL();
            oVenueRequirement_DAL.VenueRequirementId = VenueRequirementId;
            return oVenueRequirement_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWDivisionId(int DivisionId)
		{
			PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement_DAL = new PlacementManager.DAL.VenueRequirement_DAL();
			oVenueRequirement_DAL.DivisionId = DivisionId;			
			return oVenueRequirement_DAL.DeleteAllWDivisionId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWVenueId(int VenueId)
		{
			PlacementManager.DAL.VenueRequirement_DAL oVenueRequirement_DAL = new PlacementManager.DAL.VenueRequirement_DAL();
			oVenueRequirement_DAL.VenueId = VenueId;			
			return oVenueRequirement_DAL.DeleteAllWVenueId();
		}

	}
	
	public class VenueRequirementComparer : IComparer<VenueRequirement>
    {
        private string _sortColumn;
        private bool _reverse;

        public VenueRequirementComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(VenueRequirement a, VenueRequirement b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "VenueRequirementId":
					retVal = String.Compare(a.VenueRequirementId.ToString(), b.VenueRequirementId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueRequirementName":
					retVal = String.Compare(a.VenueRequirementName.ToString(), b.VenueRequirementName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueRequirementDescription":
					retVal = String.Compare(a.VenueRequirementDescription.ToString(), b.VenueRequirementDescription.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueId":
					retVal = String.Compare(a.VenueId.ToString(), b.VenueId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DivisionId":
					retVal = String.Compare(a.DivisionId.ToString(), b.DivisionId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
